package com.zxx.pattern.statePattern.state3.sample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.zxx.designpattern.R;

//登录
public class LoginState3Activity extends AppCompatActivity {

    private EditText name;
    private EditText pwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_state3);

        name = findViewById(R.id.edit_name);
        pwd = findViewById(R.id.edit_pwd);

        findViewById(R.id.btn_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                login();
                finish();
            }
        });

    }

    private void login() {
        String name = this.name.getText().toString().trim();
        String pwd = this.pwd.getText().toString().trim();
        //网络请求

        //登录成功:修改状态
        LoginContext.getLoginContext().setState(new LoginedState());

        Toast.makeText(getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show();
    }

}